﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class RepeatStatementElement : CompoundStatementElement
    {
        private ExpressionElement condition;

        public ExpressionElement Condition { get { return condition; } set { condition = value; } }

        public RepeatStatementElement(TokenInfo StartInfo, ExpressionElement Condition, List<StatementsElement> Statements, List<TokenInfo> Comments)
            : base(StartInfo, Statements, Comments)
        {
            condition = Condition;
        }

        public override string ToString()
        {
            return string.Format("repeat\r\n{0}until {1}", InnerStatements(), condition);
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            yield return condition;
            IEnumerator<ISyntaxTreeElement> baseEnumerator = base.CreateEnumerator();
            while (baseEnumerator.MoveNext())
                yield return baseEnumerator.Current;
        }
    }
}
